#ifndef _SVSTUB_H
#define _SVSTUB_H

#define _MASTER_	1
#define _SLAVE_		!_MASTER_

#include "../clsv/clsv.h"
#include "../sockcomADT/sockcomADT.h"

/* struct with server's permanent info */
typedef struct
{
	int connections;
	int capacity;
	int load;
	char db[MAX_FILENAME+1];
} serverInfoT;

/* kills zombie childs */
void reaper(int sig);

/* SIGINT handler */
void siginthandler(int sig);

/* SIGUSR1 handler */
void sigusr1handler(int sig);

/**
 ** Accepts the socket connection and forks to that a child can attend a
 ** request from the client
 **
 ** @param comm		Communications info.
 **
 **/
void do_server(Comm comm);

/**
 ** Processes TCP requests. Determines which function to call.
 **
 ** @param	comm	Communications info.
 **
 **/
void process_server(Comm comm);

/**
 ** Starts the communications session with the client on a given port and ip.
 **
 ** @param	comm	Communications info.
 ** @param	com		COMM_SERVER if called by the server, or COMM_CLIENT if
 **					called by the client.
 ** @param	host	IP of the connection.
 ** @param	port	Port to listen.
 **	@return			Return a positive value if eveything is OK, or else a negative
 **					value.
 **/
int start_session(Comm comm, commType com, char * host, char * port);

/**
 ** Takes UDP requests.
 **
 ** @param	comm	Communications info.
 **
 **/
void takeUDPResquest(Comm comm);

/**
 ** Processes UDP requests. Determines which function to call.
 **
 ** @param	p	Pointer to CLSV_BUFFER, the packet to be sent and received.
 **
 **/
void process_UDP(CLSV_BUFFER * p);

#endif

